﻿using System.Linq.Expressions;

namespace 表达式树
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //组装表达式树
            ParameterExpression para1 = Expression.Parameter(typeof(int), "x");
            ParameterExpression para2 = Expression.Parameter(typeof(int), "y");
            var paras = new ParameterExpression[] { para1, para2 };
            BinaryExpression body = Expression.Add(para1, para2);
            var expression = Expression.Lambda(body, paras);
            //编译表达式树
            var func = expression.Compile() as Func<int, int, int>;

            var res = func(1, 2);
            Console.WriteLine($"表达式的结果(1,2)=>{res}");

            //byte a = 255;
            //a+=5;
            //// a = 4
            //Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}
